package com.ruoyi.carService.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.api.domain.ReleaseInformation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.api.domain.ReleaseInformation;
import com.ruoyi.carService.service.IReleaseInformationService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 信息发布Controller
 * 
 * @author ruoyi
 * @date 2024-09-09
 */
@RestController
@RequestMapping("/information")
public class ReleaseInformationController extends BaseController
{
    @Autowired
    private IReleaseInformationService releaseInformationService;

    /**
     * 查询信息发布列表
     */
    @RequiresPermissions("carService:information:list")
    @GetMapping("/list")
    public TableDataInfo list(ReleaseInformation releaseInformation)
    {
        startPage();
        List<ReleaseInformation> list = releaseInformationService.selectReleaseInformationList(releaseInformation);
        return getDataTable(list);
    }

    /**
     * 导出信息发布列表
     */
    @RequiresPermissions("carService:information:export")
    @Log(title = "信息发布", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ReleaseInformation releaseInformation)
    {
        List<ReleaseInformation> list = releaseInformationService.selectReleaseInformationList(releaseInformation);
        ExcelUtil<ReleaseInformation> util = new ExcelUtil<ReleaseInformation>(ReleaseInformation.class);
        util.exportExcel(response, list, "信息发布数据");
    }

    /**
     * 获取信息发布详细信息
     */
    @RequiresPermissions("carService:information:query")
    @GetMapping(value = "/{riId}")
    public AjaxResult getInfo(@PathVariable("riId") Long riId)
    {
        return success(releaseInformationService.selectReleaseInformationByRiId(riId));
    }

    /**
     * 新增信息发布
     */
    @RequiresPermissions("carService:information:add")
    @Log(title = "信息发布", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ReleaseInformation releaseInformation)
    {
        // String name = SecurityUtils.getUsername();
        // releaseInformation.setRiPerson(name);
        return toAjax(releaseInformationService.insertReleaseInformation(releaseInformation));
    }

    /**
     * 修改信息发布
     */
    @RequiresPermissions("carService:information:edit")
    @Log(title = "信息发布", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ReleaseInformation releaseInformation)
    {
        return toAjax(releaseInformationService.updateReleaseInformation(releaseInformation));
    }

    /**
     * 删除信息发布
     */
    @RequiresPermissions("carService:information:remove")
    @Log(title = "信息发布", businessType = BusinessType.DELETE)
	@DeleteMapping("/{riIds}")
    public AjaxResult remove(@PathVariable Long[] riIds)
    {
        return toAjax(releaseInformationService.deleteReleaseInformationByRiIds(riIds));
    }


    //根据商铺名称和门店地址查询发布的信息
    @RequiresPermissions("carService:information:query")
    @RequestMapping("/likeQuery")
    public List<ReleaseInformation> queryReleaseByLike(ReleaseInformation releaseInformation){
        System.out.println(releaseInformationService.queryReleaseByLike(releaseInformation));
        return releaseInformationService.queryReleaseByLike(releaseInformation);
    }



    /*待审核模块 接口*/
    //查询已审核的发布信息
    @RequiresPermissions("carService:information:list")
    @RequestMapping("/unCheck")
    public TableDataInfo queryReleaseUnCheck(){
        // startPage();
        List<ReleaseInformation> list = releaseInformationService.queryReleaseUnCheck();
        return getDataTable(list);
    }

    //查询未审核的发布信息
    @RequiresPermissions("carService:information:list")
    @RequestMapping("/unCheck1")
    public TableDataInfo queryReleaseUnCheck1(){
        // startPage();
        List<ReleaseInformation> list = releaseInformationService.queryReleaseUnCheck1();
        return getDataTable(list);
    }



}
